from qiskit import QuantumCircuit
from qiskit_aer import Aer
from qiskit.visualization import plot_histogram
import matplotlib.pyplot as plt  # 新增导入

# 1. 构建贝尔态电路
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
qc.measure_all()  # 测量所有量子比特[1,5](@ref)

# 2. 执行模拟
backend = Aer.get_backend('qasm_simulator')
job = backend.run(qc, shots=1024)  # shots: 模拟次数
counts = job.result().get_counts(qc)  # 必须传入qc[5,6](@ref)

# 3. 可视化与显示
plot_histogram(counts)
plt.show()  # 新增显示命令
